﻿@model IEnumerable<Subfaculty.WebApplication.ViewModels.StudyGroupViewModel>

@{
    ViewBag.Title = "Учебные группы";
    Layout = "~/Views/Shared/_LayoutAllocation.cshtml";
}

    <script type="text/javascript">
    	function onEdit(e) {
    		$(e.form).find('#StudyArea').data('tDropDownList').select(function(dataItem) {
    			return dataItem.Text == e.dataItem['StudyArea'];
    		});
    		$(e.form).find('#StudyYear').data('tDropDownList').select(function (dataItem) {
    			return dataItem.Text == e.dataItem['StudyYear'];
    		}
			);
    	}
    </script>

@(Html.Telerik().Grid(Model)
			.Name("GridStudyGroup")
			.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new { style = "margin-left:0" }))
			.DataKeys(keys => keys.Add(c => c.Id))
			.Columns(columns =>
			{
				columns.Bound(o => o.StudyArea);
				columns.Bound(o => o.StudyYear);
				columns.Command(commands =>
				{
					commands.Edit().ButtonType(GridButtonType.BareImage);
					commands.Delete().ButtonType(GridButtonType.BareImage);
				}).Width(180).Title("Commands");
			}
			)

			.DataBinding(dataBinding =>
			{
				dataBinding.Server().Select("Index", "StudyGroup", new { ajax = true });
				dataBinding.Ajax().Select("_Index", "StudyGroup").Enabled(true);
				dataBinding.Ajax()
					.Select("SelectAjaxEditing", "StudyGroup")
					.Insert("InsertAjaxEditing", "StudyGroup")
					.Update("SaveAjaxEditing", "StudyGroup")
					.Delete("DeleteAjaxEditing", "StudyGroup");
			})
				.ClientEvents(events => events.OnEdit("onEdit"))
			.Editable(editing => editing.Mode(GridEditMode.PopUp))
			.Scrollable(scrolling => scrolling.Enabled(true))
			.Scrollable(scrolling => scrolling.Height("600px"))
			.Sortable(sorting => sorting.Enabled(true))
			.Pageable(paging => paging.Enabled(true))
			.Filterable(filtering => filtering.Enabled(true))
			.Selectable(s => s.Enabled(true))
			.Groupable(grouping => grouping.Enabled(true))
			.Footer(true))

